package com.hucc.sqlitedemo;

import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

/**
 * Created by l on 2017/5/21.
 */

public class QueryActivity extends AppCompatActivity {

   private SQLiteHelper mHelper;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_query);
        mHelper = new SQLiteHelper(this);
    }

    /**
     *  点击按钮批量插入数据
     * @param view
     */
    public void insertData(View view){
        SQLiteDatabase db = mHelper.getWritableDatabase();
        // 开启事务
        db.beginTransaction();
        for (int i=1;i<=100;i++){
            String sql = "replace into "+ Constant.TABLE_NAME+ " values("+i+", 'hucc"+i+"', 1822220)";
            db.execSQL(sql);
        }
        // 设置事务标志成功，当结束事务时就会提交事务
        db.setTransactionSuccessful();
        // 结束事务
        db.endTransaction();
        db.close();
    }
}
